
#include "head.h"
#include "key.h"

void motorpos(u8 speed,u8 dir,u8 i)
{
	u8 num=0;
	u8 tmp=i;
	u8 max=5;
	num=num+speed;
	if(num>5)
	{
		num=max;
	}
	if(num<1)
	{
		num=1;
	}
	if(dir==0)
	{
		tmp=7-tmp;
	}
	switch(tmp)
	{
		case 0:Dorange=1;Cyellow=0;Bpink=0;Ablue=0;delay_ms(num);break;
		case 1:Dorange=1;Cyellow=1;Bpink=0;Ablue=0;delay_ms(num);break;
		case 2:Dorange=0;Cyellow=1;Bpink=0;Ablue=0;delay_ms(num);break;
		case 3:Dorange=0;Cyellow=1;Bpink=1;Ablue=0;delay_ms(num);break;
		case 4:Dorange=0;Cyellow=0;Bpink=1;Ablue=0;delay_ms(num);break;
		case 5:Dorange=0;Cyellow=0;Bpink=1;Ablue=1;delay_ms(num);break;
		case 6:Dorange=0;Cyellow=0;Bpink=0;Ablue=1;delay_ms(num);break;
		case 7:Ablue=1;Bpink=0;Cyellow=0;Dorange=1;delay_ms(num);break;
		default:break;
	}
}


int main()
{
	u8 key=0;
	u8 i=0;
	u8 dir=1;
	u8 speed=1;
	while(1)
	{	
		key=key_scan();
		if(key==KEYPRESS_DIR)
		{
			dir=!dir;
		}
		motorpos(speed,dir,i++);
		if(i==8)i=0;
		if(key==KEYPRESS_ACC)
		{
			speed++;
		}
		if(key==KEYPRESS_REDU)
		{
			speed--;
		}
	}


	return 0;
}

